package cc.vv.btpartyjob.partyservice.fragment

import android.content.Intent
import android.view.View
import cc.vv.baselibrary.bean.base.BaseResponseObj
import cc.vv.baselibrary.view.banner.ImgBannerView
import cc.vv.btpartyjob.jnimodule.enums.H5UrlEnum
import cc.vv.btpartyjob.jnimodule.moudel.bean.BannerBean
import cc.vv.btpartyjob.jnimodule.moudel.resp.BannerResponseObj
import cc.vv.btpartyjob.jnimodule.server.JniDataServer
import cc.vv.btpartyjob.jnimodule.server.JniStartActivity
import cc.vv.btpartyjob.jnimodule.server.UserRoleServer
import cc.vv.btpartyjob.partyservice.R
import cc.vv.btpartyjob.partyservice.activity.*
import cc.vv.btpartyjob.partyservice.delegate.PartyServiceMainFragmentDelegate
import cc.vv.mvp.binder.BaseDataBinder
import cc.vv.mvp.fragment.BaseFragmentMVP

/**
 * 党群服务Fragment界面
 * Created by Chen.qi on 2018/10/24.
 */
class PartyServiceMainFragment : BaseFragmentMVP<PartyServiceMainFragmentDelegate>() {
    /**
     * banner所有数据集合
     */
    private var bannerList: ArrayList<BannerBean>? = null
    /**
     * banner图片集合
     */
    private var bannerPic: ArrayList<String>? = null
    /**
     * banner图片集合
     */
    private var bannerTitle: ArrayList<String>? = null

    override fun initData() {
        if (null == bannerList) {
            bannerList = ArrayList()
            bannerPic = ArrayList()
            bannerTitle = ArrayList()
            viewDelegate?.setBottomPic()
        }
        if (bannerList!!.size == 0) {
            JniDataServer.getBannerList("0", 2, true)
        }

        if (UserRoleServer.getOnlyPartyRole()) {
            viewDelegate?.showYGSZStatics(false)
            viewDelegate?.showSourceManager(false)
            viewDelegate?.showVolunteerManagerStatic(false)
        } else if (UserRoleServer.getAreaRole() || UserRoleServer.getStreetRole()
                || UserRoleServer.getSheQuRole() || UserRoleServer.getGridRole()) {
            viewDelegate?.showYGSZStatics(true)
            viewDelegate?.showSourceManager(true)
            viewDelegate?.showVolunteerManagerStatic(true)
        }
    }
    override fun bindEvenListener() {
        viewDelegate?.setOnClickListener(View.OnClickListener {
            //新闻列表
            val intent = Intent(activity, PartyGroupNewsActivity::class.java)
            startActivity(intent)
        }, R.id.ll_fpm_more)

        viewDelegate?.setOnClickListener(View.OnClickListener {
            //一岗双助--岗位查询
            val intent = Intent(activity, StationActivity::class.java)
            startActivity(intent)
        }, R.id.iv_fpm_stationOne)
        viewDelegate?.setOnClickListener(View.OnClickListener {
            //一岗双助,人员求职列表--人员查询
            val intent = Intent(activity, JobHunterListActivity::class.java)
            startActivity(intent)
        }, R.id.iv_fpm_stationTwo)
        viewDelegate?.setOnClickListener(View.OnClickListener {
            //一岗双助--统计
            JniStartActivity.startIntentWebActivity(activity, H5UrlEnum.岗位数据统计, "", "")

        }, R.id.iv_fpm_stationThree)
        viewDelegate?.setOnClickListener(View.OnClickListener {
            //志愿者库
            val intent = Intent(activity, VolunteerListActivity::class.java)
            startActivity(intent)
        }, R.id.ll_fpm_volunteerLib)
        viewDelegate?.setOnClickListener(View.OnClickListener {
            //志愿项目
            val intent = Intent(activity, VolunteerProjectActivity::class.java)
            startActivity(intent)
        }, R.id.ll_fpm_volunteerProject)
        viewDelegate?.setOnClickListener(View.OnClickListener {
            //统计
            JniStartActivity.startIntentWebActivity(activity, H5UrlEnum.志愿者统计, "", "")

        }, R.id.ll_fpm_volunteerStatics)
        viewDelegate?.setOnClickListener(View.OnClickListener {
            //资源清单
            val intent = Intent(activity, ResourceListActivity::class.java)
            startActivity(intent)
        }, R.id.rl_fpm_resourceList)
        viewDelegate?.setOnClickListener(View.OnClickListener {
            //需求清单
            val intent = Intent(activity, DemandListActivity::class.java)
            startActivity(intent)
        }, R.id.rl_fpm_demandList)

        viewDelegate?.setOnClickListener(View.OnClickListener {
            //便民服务
            val intent = Intent(activity, ServicePeopleActivity::class.java)
            startActivity(intent)
        }, R.id.iv_fpm_picOne)
        viewDelegate?.setOnClickListener(View.OnClickListener {
            //留言板
            val intent = Intent(activity, MessageBoardActivity::class.java)
            startActivity(intent)
        }, R.id.iv_fpm_picTwo)
        viewDelegate?.setOnClickListener(View.OnClickListener {
            //微心愿
            val intent = Intent(activity, TinyWishActivity::class.java)
            startActivity(intent)
        }, R.id.iv_fpm_picThree)
    }

    override fun getDelegateClass(): Class<PartyServiceMainFragmentDelegate> {
        return PartyServiceMainFragmentDelegate::class.java
    }

    override fun getDataBinder(): BaseDataBinder<*, *>? {
        return null
    }


    override fun getData(obj: BaseResponseObj<*>?) {
        super.getData(obj)
        when (obj) {
            is BannerResponseObj -> {
                val data = obj.data ?: return
                if (obj.data.records != null) {
                    bannerPic!!.clear()
                    bannerList!!.clear()
                    bannerTitle!!.clear()
                    for (i in 0 until obj.data.records.size) {
                        val bannerBean = data.records[i]
                        bannerPic!!.add(bannerBean?.cover!!)
                        bannerTitle!!.add(bannerBean?.title!!)
                        bannerList!!.add(bannerBean)
                    }
                    viewDelegate?.setBannerData(bannerPic!!, bannerTitle!!, ImgBannerView.ImgBannerClickInter { imgPath, position ->

                        JniStartActivity.startIntentWebActivity(context, H5UrlEnum.广告详情,
                                bannerList?.get(position)?.id)

//                        when (bannerList!![position].type) {
//                            0 -> {
//                                //传递id
////                                val intent = Intent(activity, WebDetailActivity::class.java)
////                                startActivity(intent)
//                                JniStartActivity.startIntentWebActivity(context, H5UrlEnum.广告详情, bannerList?.get(position)?.id)
//                            }
//                            1 -> {
//                                //没有详情
//                                JniStartActivity.startIntentWebActivity(context, H5UrlEnum.广告详情, bannerList?.get(position)?.id)
//
//                            }
//                            2 -> {
//                                //外部链接
////                                val intent = Intent(activity, WebDetailActivity::class.java)
////                                intent.getStringExtra(IntentJniKey.INTENT_KEY_WEB_TITLE)
////                                intent.getStringExtra(IntentJniKey.INTENT_KEY_WEB_URL)
////                                startActivity(intent)
//                                JniStartActivity.startIntentWebActivity(activity, H5UrlEnum.广告详情.name, bannerList?.get(position)?.url)
//                            }
//                        }
                    })
                }
            }
        }
    }

}